package org.rcgwt.client.ui.calendar.model.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.rcgwt.client.ui.calendar.i18n.CalendarLiteral;

import com.google.gwt.i18n.client.DateTimeFormat;

/**
 * A calendar event
 * 
 * @author Elian ORIOU
 * 
 */

public class Event {

	private String title;
	private String content;
	private Date startTime;
	private Date endTime;
	private String place;
	private List<String> participants;
	private EventType eventType;
	private EventFrequency eventFrequency;
	private EventColor color;

	private static DateTimeFormat format;

	public Event(String title, String content, Date start, Date end,
			String place, EventType eventType, EventFrequency frequency,
			EventColor color) {
		format = DateTimeFormat
				.getFormat(CalendarLiteral.getDateTimeLitteral());

		this.title = title;
		this.content = content;
		this.startTime = start;
		this.endTime = end;
		this.place = place;
		this.eventType = eventType;
		this.eventFrequency = frequency;
		this.color = color;
		this.participants = null;
	}

	public Event(String title, String content, String start, String end,
			String place, EventType eventType, EventFrequency frequency,
			EventColor color) {
		format = DateTimeFormat
				.getFormat(CalendarLiteral.getDateTimeLitteral());
		this.title = title;
		this.content = content;
		this.startTime = format.parse(start);
		this.endTime = format.parse(end);
		this.place = place;
		this.eventType = eventType;
		this.setFrequency(frequency);
		this.color = color;
		this.participants = null;
	}

	public Event(String title, String start, String end) {
		format = DateTimeFormat
				.getFormat(CalendarLiteral.getDateTimeLitteral());
		this.title = title;
		this.content = null;
		this.startTime = format.parse(start);
		this.endTime = format.parse(end);
		this.place = null;
		this.eventType = EventType.BUSY;
		this.eventFrequency = EventFrequency.NONE;
		this.color = null;
		this.participants = null;
	}

	public Event(String title, Date start, Date end) {
		this.title = title;
		this.content = null;
		this.startTime = start;
		this.endTime = end;
		this.place = null;
		this.eventType = EventType.BUSY;
		this.eventFrequency = EventFrequency.NONE;
		this.color = null;
		this.participants = null;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String getPlace() {
		return place;
	}

	public void setPlace(String place) {
		this.place = place;
	}

	public List<String> getParticipants() {
		return participants;
	}

	public void setParticipants(List<String> participants) {
		this.participants = participants;
	}

	public void addParticipant(String participant) {
		if (participants == null) {
			this.participants = new ArrayList<String>();
		}
		this.participants.add(participant);
	}

	public EventType getEventType() {
		return eventType;
	}

	public void setEventType(EventType eventType) {
		this.eventType = eventType;
	}

	public void setFrequency(EventFrequency eventFrequency) {
		this.eventFrequency = eventFrequency;
	}

	public EventFrequency getFrequency() {
		return eventFrequency;
	}

	public void setColor(EventColor color) {
		this.color = color;
	}

	public EventColor getColor() {
		return color;
	}

	@Override
	public String toString() {
		return "Event [color=" + color + ", content=" + content + ", endTime="
				+ endTime + ", eventFrequency=" + eventFrequency
				+ ", eventType=" + eventType + ", participants=" + participants
				+ ", place=" + place + ", startTime=" + startTime + ", title="
				+ title + "]";
	}
}
